#include <iostream>
using namespace std;

typedef struct _node_t {
    int i;
    struct _node_t *next;
} node_t;

node_t *reverse(node_t *node) {
    node_t *curr = node;
    node_t *prev = NULL;
    while (curr) {
        node_t *next = curr->next;
        curr->next = prev;
        prev = curr;
        curr = next;
    }
    return prev;
}

void print(node_t *node) {
    while (node) {
        cout << node->i << endl;
        node = node->next;
    }
}

int main() {
    node_t n4 = { 4, NULL };
    node_t n3 = { 3, &n4 };
    node_t n2 = { 2, &n3 };
    node_t n1 = { 1, &n2 };
    print(&n1);
    node_t *n = reverse(&n1);
    print(n);
    return 0;
}

